package com.jjc.android.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.jjc.android.Constants
import com.jjc.android.R
import com.jjc.android.adapter.CommonQuestionAdapter
import com.jjc.android.adapter.OperationVideoAdapter
import com.jjc.android.adapter.ProductManualAdapter
import com.jjc.android.base.BaseActivity
import com.jjc.android.entity.*
import com.jjc.android.net.SimpleHttpCallback
import com.jjc.android.util.MultiLanguageUtil
import com.jjc.android.util.SimpleOnRefreshLoadMoreListener
import com.jjc.android.util.paramEx
import com.lzy.okgo.OkGo
import com.scwang.smart.refresh.layout.SmartRefreshLayout

class CommonQuestionActivity : BaseActivity(){

    override val layoutId: Int = R.layout.activity_operation_video
    private val smartRefreshLayout: SmartRefreshLayout by lazy { findViewById<SmartRefreshLayout>(R.id.smartRefreshLayout) }
    private val recyclerView: RecyclerView by lazy { findViewById<RecyclerView>(R.id.recyclerView) }
    private lateinit var mAdapter:CommonQuestionAdapter
    private val refreshLayoutDelegate by lazy {
        object : SimpleOnRefreshLoadMoreListener(){
            override fun invokeActivity(block: BaseActivity.() -> Unit) {
                this@CommonQuestionActivity.apply(block)
            }

            override fun loadPage(
                page: Int,
                actionSuccess: (Int, List<Any>?) -> Unit,
                actionError: (Int, String?) -> Unit
            ) {
                OkGo.post<LzyResponse<PageInfo<CommonQuestionDto>>>(Constants.getFormList)
                    .paramEx(mutableMapOf("page" to page.toString(),"pagesize" to Constants.PAGE_SIZE.toString(),"needpage" to "1","formheaduuid" to "993ea78e0dc043f8a8e53fda92ddf62f","filters" to listOf<KeyValuePair>(
                        KeyValuePair("e1i8oa6zppxb2ypy", MultiLanguageUtil.getInstance().getValue("b6dc88f5-0dd3-4525-80f1-87cf92f0a56e","ecdfe448-5f60-477b-ac71-75a3711463a1"))
                    )),true)
                    .tag(this)
                    .execute(object : SimpleHttpCallback<LzyResponse<PageInfo<CommonQuestionDto>>>(false){
                        override fun onCallSuccess(response: LzyResponse<PageInfo<CommonQuestionDto>>) {
                            actionSuccess.invoke(page,response.data?.data)
                        }

                        override fun onCallError(error: String?) {
                            super.onCallError(error)
                            actionError.invoke(page,error)
                        }
                    })
            }
        }
    }
    override fun initView(savedInstanceState: Bundle?) {
        setActivityTitle(getString(R.string.questions_txt))
        recyclerView.layoutManager = LinearLayoutManager(this)
        mAdapter = CommonQuestionAdapter()
        recyclerView.adapter = mAdapter
        refreshLayoutDelegate.init(smartRefreshLayout,recyclerView,false)
    }
}